<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="layui-v2.7.6/layui/css/layui.css">
    <link rel="stylesheet" href="layui-v2.7.6/layui/css/public.css">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label required">昵称：</label>
        <div class="layui-input-block">
            <input type="text" name="uname" lay-verify="required" lay-reqtext="昵称不能为空" placeholder="" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">密码：</label>
        <div class="layui-input-block">
            <input type="password" name="upwd" placeholder="请输入密码" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">确认密码：</label>
        <div class="layui-input-block">
            <input type="password" name="confirm_password" placeholder="请再次输入密码" required lay-verify="required|confirmPassword" autocomplete="new-password" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">角色：</label>
        <div class="layui-input-block">
            <input type="radio" name="utype" value="0" title="普通人员" checked="">
            <input type="radio" name="utype" value="1" title="管理人员">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">备注：</label>
        <div class="layui-input-block">
            <input type="text" name="umemo" placeholder="请输入备注" value="" class="layui-input">
        </div>
    </div>


    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">新增用户</button>
        </div>
    </div>
</div>
<script src="layui-v2.7.6/layui/layui.js"></script>
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script>
    layui.use(['form','upload'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        // 自定义表单验证规则
        form.verify({
            confirmPassword: function(value, item){
                var upwd = $('input[name="upwd"]').val();
                if(value !== upwd){
                    return '两次输入的密码不一致!';
                }
            }
        });

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            //新增用户 Ajax 请求接口
            $.post('http://localhost:8080/api/user/add.do',data.field,function (res){
                if(res.code==0){
                    //成功
                    // 关闭弹出层
                    layer.close(index);
                    var iframeIndex = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(iframeIndex);
                    layer.msg("亲,添加成功！");
                }else {
                    layer.msg("亲。新增失败！");
                }
            })
            return false;
        });
    });
</script>
</body>
</html>